package com.itheima02;

import java.lang.reflect.Field;

public class Test03 {

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {

        Student stu = new Student("张三", 23);

        Object val = getProperty(stu, "name");

        System.out.println(val);
    }




    public static Object getProperty(Object obj,String propertyName) throws NoSuchFieldException, IllegalAccessException {

        Class c = obj.getClass();

        Field f = c.getDeclaredField(propertyName);

        f.setAccessible(true);

        Object fv = f.get(obj);

        return fv;
    }
}
